package com.yjd.comm.base.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

/**
 * <b>description</b>：耗时统计 <br>
 * <b>time</b>：2015-3-9下午2:21:31 <br>
 * <b>author</b>： ready likun_557@163.com
 */
public class CostTimeFilter implements Filter {
	private Logger logger = Logger.getLogger(CostTimeFilter.class);

	@Override
	public void destroy() {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		logger.info(String.format("本次请求start[  %s   ]",
				((HttpServletRequest) request).getRequestURL()));
		long startTime = System.currentTimeMillis();
		chain.doFilter(request, response);
		logger.info(String.format("本次请求end[  %s   ]耗时(ms):%s",
				((HttpServletRequest) request).getRequestURL(),
				(System.currentTimeMillis() - startTime)));

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
	}
}
